package com.xzit.day04.controller;

import com.xzit.day04.entity.Emp;
import com.xzit.day04.service.EmpService;
import com.xzit.day04.service.EmpServicePlus;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/emp-plus")
@Tag(name = "员工管理(plus版)", description = "员工信息的增删改查")
public class EmpControllerPlus {
    @Autowired
    private EmpServicePlus empService;
    @Operation(summary = "新增员工")
    @PostMapping("/add")
    public String addEmp(@RequestBody Emp emp) {
        int result = empService.addEmp(emp);
        return result > 0 ? "添加成功" : "添加失败";
    }
    @Operation(summary = "根据ID删除员工")
    @DeleteMapping("/delete/{id}")
    public String deleteEmp(@PathVariable int id) {
        int result = empService.deleteEmpById(id);
        return result > 0 ? "删除成功" : "删除失败";
    }
    @Operation(summary = "查询全部员工")
    @GetMapping("/list")
    public List<Emp> findAll() {
        return empService.getAllEmps();
    }


}
